package model

import (
	"database/sql"
	"time"

	"github.com/guregu/null"
	"github.com/satori/go.uuid"
)

var (
	_ = time.Second
	_ = sql.LevelDefault
	_ = null.Bool{}
	_ = uuid.UUID{}
)

/*
DB Table Details
-------------------------------------


CREATE TABLE "playlist_track"
(
    [PlaylistId] INTEGER  NOT NULL,
    [TrackId] INTEGER  NOT NULL,
    CONSTRAINT [PK_PlaylistTrack] PRIMARY KEY  ([PlaylistId], [TrackId]),
    FOREIGN KEY ([PlaylistId]) REFERENCES "playlists" ([PlaylistId])
		ON DELETE NO ACTION ON UPDATE NO ACTION,
    FOREIGN KEY ([TrackId]) REFERENCES "tracks" ([TrackId])
		ON DELETE NO ACTION ON UPDATE NO ACTION
)

JSON Sample
-------------------------------------
{    "playlist_id": 45,    "track_id": 82}



*/

// PlaylistTrack struct is a row record of the playlist_track table in the main database
type PlaylistTrack struct {
	//[ 0] PlaylistId                                     integer              null: false  primary: true   isArray: false  auto: false  col: integer         len: -1      default: []
	PlaylistID int32 `gorm:"primary_key;column:PlaylistId;type:integer;" json:"playlist_id"`
	//[ 1] TrackId                                        integer              null: false  primary: false  isArray: false  auto: false  col: integer         len: -1      default: []
	TrackID int32 `gorm:"column:TrackId;type:integer;" json:"track_id"`
}

var playlist_trackTableInfo = &TableInfo{
	Name: "playlist_track",
	Columns: []*ColumnInfo{

		&ColumnInfo{
			Index:              0,
			Name:               "PlaylistId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       true,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "PlaylistID",
			GoFieldType:        "int32",
			JSONFieldName:      "playlist_id",
			ProtobufFieldName:  "playlist_id",
			ProtobufType:       "int32",
			ProtobufPos:        1,
		},

		&ColumnInfo{
			Index:              1,
			Name:               "TrackId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "TrackID",
			GoFieldType:        "int32",
			JSONFieldName:      "track_id",
			ProtobufFieldName:  "track_id",
			ProtobufType:       "int32",
			ProtobufPos:        2,
		},
	},
}

// TableName sets the insert table name for this struct type
func (p *PlaylistTrack) TableName() string {
	return "playlist_track"
}

// BeforeSave invoked before saving, return an error if field is not populated.
func (p *PlaylistTrack) BeforeSave() error {
	return nil
}

// Prepare invoked before saving, can be used to populate fields etc.
func (p *PlaylistTrack) Prepare() {
}

// Validate invoked before performing action, return an error if field is not populated.
func (p *PlaylistTrack) Validate(action Action) error {
	return nil
}

// TableInfo return table meta data
func (p *PlaylistTrack) TableInfo() *TableInfo {
	return playlist_trackTableInfo
}
